import Vue from 'vue'

export function mixin (...mixins) {
  return target => {
    if (!(target.prototype instanceof Vue)) {
      throw new SyntaxError(`@Mixin() class ${target.name} must inherit Vue or its descendant class when class property is used.`)
    }

    if (typeof mixins[0] === 'function') {
      throw new SyntaxError(`@Mixin() class ${target.name} requires at least one mixin as an argument`)
    }

    const options = {}

    mixins.forEach(_mixin => {
      Reflect.ownKeys(_mixin).forEach(property => {
        options[property] = _mixin[property]
      })
    })

    return target.prototype.constructor.extend(options)
  }
}
